/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package intelligenttm;



import Data.ThematicData;
import Carto.Carto;
import Data.Rating;
import Data.rankTypeEnum;
import intelligenttm.ITMCarto.BaseData;
import intelligenttm.ITMCarto.S1SelectMapController;
import intelligenttm.ITMCarto.S2InputDataController;
import intelligenttm.ITMCarto.S3SelectionTypeController;
import intelligenttm.ITMCarto.SHierarchicalStatisticalGraphController;
import intelligenttm.ITMCarto.SPartitionSatisticalGraphController;
import intelligenttm.InPutDlg.AddFenQuDlgController;
import intelligenttm.InPutDlg.ChangeFenJiController;
import intelligenttm.InPutDlg.ChangeFenQuController;
import intelligenttm.InPutDlg.SavePicControl;
import intelligenttm.InPutDlg.SavePicControlDlgController;
import intelligenttm.SourceFile.CartoType;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;

import java.util.*;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;

import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TabPane;
import javafx.scene.control.ToolBar;
import javafx.scene.control.TreeView;
import javafx.scene.layout.BorderPane;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import me.aviator.entity.HibernateUtil;
import me.aviator.entity.MBasemap;
import me.aviator.entity.Ribbon;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.transcoder.TranscoderException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * FXML Controller class
 *
 * @author 望舒凌霄
 */
public class ITMGUIMainController implements Initializable {
    @FXML
    private BorderPane RootBorderPane;
    @FXML
    private MenuItem UIMainMenuFileNew;
    @FXML
    private MenuItem UIMainMenuFileOpen;
    @FXML
    private MenuItem UIMainMenuFileSave;
    @FXML
    private MenuItem UIMainMenuFileSaveAs;
    @FXML
    private MenuItem UIMainMenuFilePrint;
    @FXML
    private MenuItem UIMainMenuFileClose;
    @FXML
    private MenuItem UIMainMenuEditUndo;
    @FXML
    private MenuItem UIMainMenuEditRedo;
    @FXML
    private MenuItem UIMainMenuEditDelete;
    @FXML
    private MenuItem UIMainMenuEditCut;
    @FXML
    private MenuItem UIMainMenuEditCopy;
    @FXML
    private MenuItem UIMainMenuEditPaste;
    @FXML
    private MenuItem UIMainMenuCartoBegin;
    @FXML
    private MenuItem UIMainMenuCartoEdit;
    @FXML
    private MenuItem UIMainMenuInsertWord;
    @FXML
    private MenuItem UIMainMenuInsertPic;
    @FXML
    private MenuItem UIMainMenuInsertAllChart;
    @FXML
    private MenuItem UIMainMenuInsertOneChart;
    @FXML
    private RadioMenuItem UIMainMenuViewZoomIn;
    @FXML
    private RadioMenuItem UIMainMenuViewZoomOut;
    @FXML
    private RadioMenuItem UIMainMenuViewPan;
    @FXML
    private MenuItem UIMainMenuViewGlobal;
    @FXML
    private MenuItem UIMainMenuHelpDoc;
    @FXML
    private MenuItem UIMainMenuHelpAbout;
    @FXML
    private ToolBar UIMainToolBar;
    @FXML
    private Button UIMainToolBarNew;
    @FXML
    private Button UIMainToolBarOpen;
    @FXML
    private Button UIMainToolBarSave;
    @FXML
    private Button UIMainToolBarPrint;
    @FXML
    private Button UIMainToolBarBeginCarto;
    @FXML
    private Button UIMainToolBarSelect;
    @FXML
    private Button UIMainToolBarPan;
    @FXML
    private Button UIMainToolBarZoomIn;
    @FXML
    private Button UIMainToolBarZoomOut;
    @FXML
    private Button UIMainToolBarSetting;
    @FXML
    private TreeView<String> UIMainTOC;
    @FXML
    private Label UIMainBottomLabel;
    @FXML
    private TabPane UIMainTabPane;
    @FXML
    private MenuItem UIMainMenuFileOutPut;
    @FXML
    private Button UIMainToolBarGlogal;
    @FXML
    private SplitPane UIMainSplitPane;
    
    @FXML
    private MenuItem TreeViewRightClick;
    
    /**
     * Initializes the controller class.
     */
    List<SVGCarto> SVGCartoList=new ArrayList<>();
    
    DocNumCount SVGDocNumCount=new DocNumCount(0,0);
    public int NowDocIndex=0;
    SavePicControl SPC=new SavePicControl();
    List DocTabList = new ArrayList();
    ITMUIMethod UIMethod=new ITMUIMethod();
    SavePicControlDlgController MyController=new SavePicControlDlgController();
    int symbolcount=0;
    
    
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        SVGCartoList.clear();
        UIMethod.UIMainNewFile(SVGDocNumCount, SVGCartoList, DocTabList, UIMainTabPane);
    }

    @FXML
    private void HandleUIMainToolBarNew(ActionEvent event) throws IOException {
        UIMethod.UIMainNewFile(SVGDocNumCount, SVGCartoList, DocTabList, UIMainTabPane);  
    }

    @FXML
    private void HandleUIMainToolBarOpen(ActionEvent event) throws IOException, InterruptedException {
        NowDocIndex=UIMethod.UITabPaneSelectedTab(UIMainTabPane);
        UIMethod.UIMainOpenFile(SVGCartoList,SVGDocNumCount,NowDocIndex,DocTabList,UIMainTabPane,UIMainTOC);
    }

    @FXML
    private void HandleUIMainToolBarSave(ActionEvent event) throws IOException, MalformedURLException, FileNotFoundException, TranscoderException {
        NowDocIndex=UIMethod.UITabPaneSelectedTab(UIMainTabPane);
        SVGCarto OutSVGImage=SVGCartoList.get(NowDocIndex);
        String SaveType="Save";
        UIMethod.UIMainSaveFile(OutSVGImage);
    }

    private void HandleUIMainTabPaneOnMouseClicked(MouseEvent event) {
        NowDocIndex=UIMethod.UITabPaneSelectedTab(UIMainTabPane);
    }

    @FXML
    private void HandleUIMainToolBarPrint(ActionEvent event) throws IOException {
//        FXMLLoader fXMLLoader1 = new FXMLLoader(getClass().getResource("/DatabaseManeger/MBaseMap.fxml"));
//        Parent root1=fXMLLoader1.load();
//        Scene scene1 = new Scene(root1);
//        Stage stage1 = new Stage();
//        stage1.setTitle("保存底图");
//        stage1.setScene(scene1);
//        stage1.showAndWait();
    }
    
    @FXML
    private void HandleUIMainMenuFileSaveAs(ActionEvent event) throws IOException, MalformedURLException, FileNotFoundException, TranscoderException {
        NowDocIndex=UIMethod.UITabPaneSelectedTab(UIMainTabPane);
        SVGCarto OutSVGImage=SVGCartoList.get(NowDocIndex);
        String SaveType="SaveAs";
        UIMethod.UIMainSaveAsFile(OutSVGImage,SaveType);
    }
    
     @FXML
    private void HandleUIMainMenuFileOutPut(ActionEvent event) throws IOException, MalformedURLException, FileNotFoundException, TranscoderException {
        NowDocIndex=UIMethod.UITabPaneSelectedTab(UIMainTabPane);
        SVGCarto OutSVGImage=SVGCartoList.get(NowDocIndex);
        String SaveType="OutPut";
        UIMethod.UIMainSaveAsFile(OutSVGImage,SaveType);
    }
    
    @FXML
    private void HandleUIMainMenuFileClose(ActionEvent event) {
        RootBorderPane.getScene().getWindow().hide();
    }
    
    
    
    @FXML
    private void HandleUIMainToolBarBeginCarto(ActionEvent event) throws IOException, InterruptedException, TransformerException {
        List<String> MakeCartoList=new ArrayList<>();
        MakeCartoList.add("底图选择");
        MakeCartoList.add("数据导入");
        MakeCartoList.add("类型选择");
        MBasemap BM=null;
        List<BaseData> BDList=null;
        List<CartoType> CTList=null;
        
        Color BColor=null;
        //fenji
        //List<FenJiCartoType> FenJiColorList = null;
        Ribbon FenJiRibbon=null;
        String FenJiAttribute=null;
        //
        List<AddFenQuDlgController> FenQuTypeList=null;
        for(int i=0;i<MakeCartoList.size();i++){
            switch (MakeCartoList.get(i)){
                case "底图选择":{
                    S1SelectMapController BMC;
                    BMC=UIMethod.Step1ChooseBaseMap(BM);
                    BM=BMC.getBM();
                    if(BMC.getWhichBtn()==-1){
                        i=i-2;
                    }
                    else if(BMC.getWhichBtn()==0){
                        return;
                    }
                    break;
                }
                case "数据导入":{
                    S2InputDataController BDC;
                    BDC=UIMethod.Step2InputData(BDList);
                    BDList=BDC.getDataList();
                    if(BDC.getWhichBtn()==-1){
                        i=i-2;
                    }
                    else if(BDC.getWhichBtn()==0){
                        return;
                    }
                    break;
                }
                case "类型选择":{
                    S3SelectionTypeController CTC;
                    CTC=UIMethod.Step3SelectionType(CTList);
                    CTList=CTC.getCartoTypeList();
                    if(CTC.getWhichBtn()==-1){
                        i=i-2;
                    }
                    else if(CTC.getWhichBtn()==0){
                        return;
                    }
                    if(MakeCartoList.size()>3){
                        MakeCartoList.clear();
                        MakeCartoList.add("底图选择");
                        MakeCartoList.add("数据导入");
                        MakeCartoList.add("类型选择");
                    }
                    
                    for(int j=0;j<CTList.size();j++){
                        MakeCartoList.add(CTList.get(j).getTypeName());
                    }
                    break;
                }
                case "分级统计图法":{
                    SHierarchicalStatisticalGraphController SHSG;
                    SHSG=UIMethod.SHierarchicalStatisticalGraph(BDList);
//                    FenJiColorList=SHSG.getFenJiColorList();
                    FenJiRibbon=SHSG.getRibbonColor();
                    FenJiAttribute=SHSG.getAttributeString();
                    if(SHSG.getWhichBtn()==-1){
                        i=i-2;
                    }
                    else if(SHSG.getWhichBtn()==0){
                        return;
                    }
                    break;
                    
                }
                case "分区统计图表法":{
                    SPartitionSatisticalGraphController SPSG;
                    SPSG=UIMethod.SPartitionSatisticalGraph(BDList);
                    FenQuTypeList=SPSG.getFenQuCartoTypeList();
                    if(SPSG.getWhichBtn()==-1){
                        i=i-2;
                    }
                    else if(SPSG.getWhichBtn()==0){
                        return;
                    }
                    break;
                    
                }
            } 
        }
        Carto carto=new Carto(BM);
        carto.setBDList(BDList);
        
        SVGCarto svgCarto=null;
        
        for(String str:MakeCartoList){
            switch(str){
                case "分级统计图法":
                    ArrayList<Double> fenjidata=null;
                    for(int i=0;i<BDList.size();i++){
                        ThematicData TD= BDList.get(i).getData();
                        fenjidata=TD.GetColdouble(FenJiAttribute);
                    }
                    carto.setFenJiRibbon(FenJiRibbon);
                    carto.setFenJiAttribute(FenJiAttribute);
                    Rating rate=new Rating(fenjidata,FenJiRibbon.getNum(),rankTypeEnum.EqualInterval);
                    svgCarto=carto.levelBackground(rate.getRatingResult(), FenJiRibbon);
                    
                    
                    
                    break;
                case "分区统计图表法":
                    for(AddFenQuDlgController con:FenQuTypeList){
                        carto.addSymbolLayerList(con);
                        ArrayList<String> names=null;
                        switch(con.getFenQuType()){
                            case "饼状图":
                                List<List<Double>> fenqudata=new ArrayList<>();
                                for(int i=0;i<BDList.size();i++){
                                    ThematicData TD= BDList.get(i).getData();
                                    //改成多张表
                                    fenqudata=TD.GetMutiColdoubleByNameTS(con.getAttributeList());
                                    if(!fenqudata.isEmpty()){
                                        names=TD.GetColString(0);
                                    }
                                }
                                
                                if(con.isIs3D())
                                {
                                    symbolcount=symbolcount+1;
                                    String id="Pie3D-"+symbolcount;
                                    carto.addSymbolIDList(id);
                                    svgCarto=carto.drawPieChart3D(fenqudata, con.getRibbonColor(),symbolcount);
                                }
                                else
                                {
                                    symbolcount=symbolcount+1;
                                    String id="Pie-"+symbolcount;
                                    carto.addSymbolIDList(id);
                                    svgCarto=carto.drawPieChart(fenqudata,con.getRibbonColor(),symbolcount);
                                   
                                }
                                break;
                            case "条形图":
                                List<List<Double>> fenqudata2=new ArrayList<>();
                                for(int i=0;i<BDList.size();i++){
                                    ThematicData TD= BDList.get(i).getData();
                                    //改成多张表
                                    fenqudata2=TD.GetMutiColdoubleByNameTS(con.getAttributeList());
                                    if(!fenqudata2.isEmpty()){
                                        names=TD.GetColString(0);
                                    }
                                }
                                symbolcount=symbolcount+1;
                                String id="Bar-"+symbolcount;
                                carto.addSymbolIDList(id);
                                svgCarto=carto.drawBarChart(fenqudata2, con.getRibbonColor(),symbolcount);
                                
                                break;
                            case "自定义":
                                List<Double> data=new ArrayList<>();
                                for(int i=0;i<BDList.size();i++){
                                    ThematicData TD= BDList.get(i).getData();
                                    data=TD.GetColdouble(con.getAttributeList().get(0));
                                    if(!data.isEmpty()){
                                        names=TD.GetColString(0);
                                    }
                                }
                                symbolcount=symbolcount+1;
                                String Artid="ArtSymbol-"+symbolcount;
                                carto.addSymbolIDList(Artid);
                                svgCarto=carto.drawArtSymbol(data, con.getChoosedSymbol(),symbolcount);
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                default:
                    break;
            }
            
        }
        
//        UIMethod.UIMainNewFile(SVGDocNumCount, SVGCartoList, DocTabList, UIMainTabPane);  
//        NowDocIndex=SVGDocNumCount.getDocNum()-1;
        
        //Thread.sleep(5000);
        SVGCartoList.set(NowDocIndex, svgCarto);
        //shuchu
        Document doc=svgCarto.getSvgDocument();
        Source source = new DOMSource(doc);  
        File F=new File("D:/Temp.svg");
        
        DOMSource doms = new DOMSource(doc);
        FileOutputStream outstream = new FileOutputStream(F);
        StreamResult result = new StreamResult(outstream);  
        Transformer transformer = TransformerFactory.newInstance().newTransformer();  
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");  
        transformer.transform(source, result);  
        
        SVGCarto TempSVG=new SVGCarto("file:/D:/Temp.svg");
        
        JSVGCanvas svgCanvas = new JSVGCanvas();
        svgCanvas.setDocument(TempSVG.getSvgDocument());
        SwingNode SNsvgCanvas=new SwingNode ();
        Thread.sleep(2500);
        svgCanvas.resize(10, 10);
        SNsvgCanvas.setContent(svgCanvas);
        ((ScrollPane)(UIMainTabPane.getTabs().get(NowDocIndex).getContent())).setContent(SNsvgCanvas);
//        ((StackPane)UIMainTabPane.getTabs().get(NowDocIndex).getContent()).getChildren().add(SNsvgCanvas);
        UIMainTabPane.getTabs().get(NowDocIndex).setText(SVGCartoList.get(NowDocIndex).getBasedSVGName());
        
        SVGCarto SVG=SVGCartoList.get(NowDocIndex);
        if(SVG!=null){
            UIMethod.SetTOCTreeVew(SVG, UIMainTOC);
        }
        else{
            UIMainTOC.setRoot(null);
        }
        //UIMethod.UIRefreashNowSVGCanvas(SVGCartoList, NowDocIndex, UIMainTabPane);
    }

    private void HandleUIMainMenuCartoSelect(ActionEvent event) {
        SessionFactory sf=HibernateUtil.getSessionFactory();
        Session sess=sf.openSession();
        Transaction tx=sess.beginTransaction();
        
//        MBasemap basemap= (MBasemap) sess.load(MBasemap.class, new Integer(0));
        Ribbon ribbon=(Ribbon)sess.load(Ribbon.class,0);
        
        tx.commit();
        System.out.print(ribbon.getColorlist().get(0).getRed());
        
//        SVGDocument  svgDocument =(SVGDocument) doc;
//        svgCanvas.setDocument((Document)svgDocument);
//        SwingNode SNsvgCanvas=new SwingNode ();
//        SNsvgCanvas.setContent(svgCanvas);
//        ((StackPane)UIMainTabPane.getTabs().get(NowDocIndex).getContent()).getChildren().add(SNsvgCanvas);
        //UIMainTabPane.getTabs().get(NowDocIndex).setText(SVGCartoList.get(NowDocIndex).getBasedSVGName());
        sess.close();
        sf.close();
    }

    private void HandleUIMainMenuSetting(ActionEvent event) {
        try {
            FXMLLoader fXMLLoader1 = new FXMLLoader(getClass().getResource("/DatabaseManeger/RibbonForm.fxml"));
            Parent root1=fXMLLoader1.load();
            Scene scene1 = new Scene(root1);
            Stage stage1 = new Stage();
            stage1.setTitle("色带保存");
            stage1.setScene(scene1);
            stage1.showAndWait();
        } catch (IOException ex) {
            Logger.getLogger(ITMGUIMainController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void HandleUIMainMenuGlobal(ActionEvent event) throws IOException {
         FXMLLoader fXMLLoader1 = new FXMLLoader(getClass().getResource("/DatabaseManeger/SymbolForm.fxml"));
        Parent root1=fXMLLoader1.load();
        Scene scene1 = new Scene(root1);
        Stage stage1 = new Stage();
        stage1.setTitle("符号保存");
        stage1.setScene(scene1);
        stage1.showAndWait();
    }
    
    @FXML
    private void HandleIfTabChange(MouseEvent event) {
        int tNowDocIndex=UIMethod.UITabPaneSelectedTab(UIMainTabPane);
        if(tNowDocIndex!=NowDocIndex){
            NowDocIndex=tNowDocIndex;
            SVGCarto SVG=SVGCartoList.get(NowDocIndex);
            if(SVG!=null){
                UIMethod.SetTOCTreeVew(SVG, UIMainTOC);
            }
            else{
                UIMainTOC.setRoot(null);
            }
        }
    }

    @FXML
    private void HandleUIMainToolBarGlogal(ActionEvent event) throws IOException {
         FXMLLoader fXMLLoader1 = new FXMLLoader(getClass().getResource("/DatabaseManeger/SymbolForm.fxml"));
        Parent root1=fXMLLoader1.load();
        Scene scene1 = new Scene(root1);
        Stage stage1 = new Stage();
        stage1.setTitle("符号保存");
        stage1.setScene(scene1);
        stage1.showAndWait();
    }

    @FXML
    private void HandleUIMainToolBarSetting(ActionEvent event) {
    }

    @FXML
    private void HandleTreeViewRightClick(ActionEvent event) throws IOException, InterruptedException, TransformerException {
        String ID=UIMainTOC.getFocusModel().getFocusedItem().getValue();
        
        String RID=ID.substring(ID.indexOf("_")+1,ID.length());
        
        SVGCarto SVG=SVGCartoList.get(NowDocIndex);
        List<BaseData> BDList=SVG.getBDList();
        String Tid=RID;
        try{
            Tid=RID.substring(0, RID.lastIndexOf("-"));
        }catch(Exception e){
        };
        Carto carto=null;
        SVGCarto svgCarto=null;
        switch (Tid) {
            case "Prov_R":
                FXMLLoader fXMLLoader = new FXMLLoader(getClass().getResource("/intelligenttm/InPutDlg/ChangeFenJi.fxml"));
                Parent root=fXMLLoader.load();
                ChangeFenJiController MyC;
                MyC=fXMLLoader.getController();
                MyC.SetRibbonLevel(SVG.getFenJiRibbon().getNum());
                
                
                Scene scene = new Scene(root);
                Stage stage = new Stage();
                stage.setTitle("类型选择");
                stage.setScene(scene);
                stage.showAndWait();
                
                carto=new Carto(SVG);
                ArrayList<Double> fenjidata=null;
                for(int i=0;i<BDList.size();i++){
                    ThematicData TD= BDList.get(i).getData();
                    fenjidata=TD.GetColdouble(SVG.getFenJiAttribute());
                }
                carto.setFenJiRibbon(MyC.getRibbonColor());
                carto.setFenJiAttribute(SVG.getFenJiAttribute());
                Rating rate=new Rating(fenjidata,MyC.getRibbonColor().getNum(),rankTypeEnum.EqualInterval);
                svgCarto=carto.levelBackground(rate.getRatingResult(), MyC.getRibbonColor());
                break;
            case "Pie":
            case "Pie3D":
            case "Bar":
                NodeList ND=SVG.getSvgDocument().getRootElement().getChildNodes();
                int DeletIndex=-1;
                for(int i=0;i<ND.getLength();i++){
                    Node N=ND.item(i);
                    if(UIMethod.isSVGElementNodeName(N.getNodeName())){
                        String Eid=((Element)N).getAttribute("id");
                        if (RID.equals(Eid)){
                            DeletIndex=i;
                            break;
                        }
                    }
                }
                if(DeletIndex>=0){
                    SVG.getSvgDocument().getRootElement().removeChild(ND.item(DeletIndex));
                    int FenQuIndex=SVG.getSymbolIDList().indexOf(RID);
                    AddFenQuDlgController con=SVG.getSymbolLayerList().get(FenQuIndex);
                    
                    
                    
                    FXMLLoader fXMLLoader1 = new FXMLLoader(getClass().getResource("/intelligenttm/InPutDlg/ChangeFenQu.fxml"));
                    Parent root1=fXMLLoader1.load();
                    ChangeFenQuController MyController;
                    MyController=fXMLLoader1.getController();
                    MyController.SetRibbonLevel(con.getRibbonColor().getNum());

                    Scene scene1 = new Scene(root1);
                    Stage stage1 = new Stage();
                    stage1.setTitle("类型选择");
                    stage1.setScene(scene1);
                    stage1.showAndWait();
                    
                    con.setFenQuType(MyController.getFenQuType());
                    con.setRibbonColor(MyController.getRibbonColor());
                    con.setIs3D(MyController.isIs3D());
                    ////
                    
                    carto=new Carto(SVG);
                    carto.addSymbolLayerList(con);
                    ArrayList<String> names=null;
                    switch(con.getFenQuType()){
                        case "饼状图":
                            List<List<Double>> fenqudata=new ArrayList<>();
                            for(int i=0;i<BDList.size();i++){
                                ThematicData TD= BDList.get(i).getData();
                                //改成多张表
                                fenqudata=TD.GetMutiColdoubleByNameTS(con.getAttributeList());
                                if(!fenqudata.isEmpty()){
                                    names=TD.GetColString(0);
                                }
                            }

                            if(con.isIs3D())
                            {
                                symbolcount=symbolcount+1;
                                String id="Pie3D-"+symbolcount;
                                carto.addSymbolIDList(id);
                                svgCarto=carto.drawPieChart3D(fenqudata, con.getRibbonColor(),symbolcount);
                            }
                            else
                            {
                                symbolcount=symbolcount+1;
                                String id="Pie-"+symbolcount;
                                carto.addSymbolIDList(id);
                                svgCarto=carto.drawPieChart(fenqudata,con.getRibbonColor(),symbolcount);

                            }
                            break;
                        case "条形图":
                            List<List<Double>> fenqudata2=new ArrayList<>();
                            for(int i=0;i<BDList.size();i++){
                                ThematicData TD= BDList.get(i).getData();
                                //改成多张表
                                fenqudata2=TD.GetMutiColdoubleByNameTS(con.getAttributeList());
                                if(!fenqudata2.isEmpty()){
                                    names=TD.GetColString(0);
                                }
                            }
                            symbolcount=symbolcount+1;
                            String id="Bar-"+symbolcount;
                            carto.addSymbolIDList(id);
                            svgCarto=carto.drawBarChart(fenqudata2, con.getRibbonColor(),symbolcount);
                            break;
                    }
                    ////
                    SVGCartoList.set(NowDocIndex, SVG);
                    
                }
                break;
            case "ArtSymbol":
                break;
        }
        
        try{
            Document doc=svgCarto.getSvgDocument();
            Source source = new DOMSource(doc);  
            File F=new File("D:/Temp.svg");

            DOMSource doms = new DOMSource(doc);
            FileOutputStream outstream = new FileOutputStream(F);
            StreamResult result = new StreamResult(outstream);  
            Transformer transformer = TransformerFactory.newInstance().newTransformer();  
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");  
            transformer.transform(source, result);  

            SVGCarto TempSVG=new SVGCarto("file:/D:/Temp.svg");

            JSVGCanvas svgCanvas = new JSVGCanvas();
            svgCanvas.setDocument(TempSVG.getSvgDocument());
            SwingNode SNsvgCanvas=new SwingNode ();
            Thread.sleep(2500);
            svgCanvas.resize(10, 10);
            SNsvgCanvas.setContent(svgCanvas);
            ((ScrollPane)(UIMainTabPane.getTabs().get(NowDocIndex).getContent())).setContent(SNsvgCanvas);
    //        ((StackPane)UIMainTabPane.getTabs().get(NowDocIndex).getContent()).getChildren().add(SNsvgCanvas);
            UIMainTabPane.getTabs().get(NowDocIndex).setText(SVGCartoList.get(NowDocIndex).getBasedSVGName());

            SVGCarto NowSVG=SVGCartoList.get(NowDocIndex);
            if(SVG!=null){
                UIMethod.SetTOCTreeVew(NowSVG, UIMainTOC);
            }
            else{
                UIMainTOC.setRoot(null);
            }
        }
        catch(Exception e){
            
        }
    }
}

